#!/usr/bin/perl
use warnings;
use strict;
use Pod::Usage;
use Data::Dumper;
BEGIN {
    use File::Basename;
    my $path = dirname($0);
    $path = '.' unless defined $path && $path ne '';
    push @INC, $path;
}

### user modules
use CommandLine;
use SimpleError;

### options definition
my %options = (
    'input'          => +{ option => 'input|i=s'             , value =>    undef, check => 1 },
    'output'         => +{ option => 'output|o=s'            , value =>    undef, },
    #--
    'type'           => +{ option => 'type!t=s'              , value =>    'klt', },
    #--
    'FS'             => +{ option => 'field-separator|T=s'   , value =>      ',', },
);
use constant OPTION_DEFAULT => '.';
my %option_defaults = (
    'output'         => +{ reference => 'input', value => '*.tma'       , base => 1, },
    'FS'             => +{ force => 1, value => sub {
                                                my $sep = shift; $sep =~ s/\.s/ /g;
                                                $sep =~ s/\.t/\t/g; return $sep; },  },
);

### command line interface
pod2usage(-exitstatus => 0, -verbose => 1) if @ARGV == 0;
CommandLine::get_options( \%options, 'config' );
pod2usage(-exitstatus => 0, -verbose => 1) if $options{'help'}{'value'};
pod2usage(-exitstatus => 0, -verbose => 2) if $options{'manual'}{'value'};
CommandLine::apply_checks( \%options );
CommandLine::apply_defaults( \%option_defaults,  \%options, OPTION_DEFAULT );
#message( "options with defaults applied:" );
#CommandLine::print_options( \%options );
